package com.zhangj.alljuc.threadpool;

import java.util.concurrent.*;

/**
 * @ClassName MyThreadPoolTest3
 * @Description
 * @Author zhangjie
 * @Date 2022/3/9 21:27
 * @Version 1.0
 */

public class MyThreadPoolTest3 {

    public static void main(String[] args) {


        ExecutorService executorService = new ThreadPoolExecutor(
                2,
                5,
                3L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(4),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());

        try {
            for (int i = 1; i <= 10; i++) {
                executorService.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + "正在办理业务");
                });

                // TimeUnit.SECONDS.sleep(3);

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executorService.shutdown();
        }
    }
}